
    /**  
    * @Title: AlipayRequest.java
    * @Package com.third.alipay.util
    * @Description: 
    * @author likai
    * @date 2017年10月15日
    * @version V1.0  
    */
    
package com.third.base.ali;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
    * @ClassName: AlipayRequest
    * @Description: 支付请求数据
    * @author likai
    * @date 2017年10月15日
    *
    */

public class AlipayRequest{
	public static Logger log = LoggerFactory.getLogger(AlipayRequest.class);

	//hb_fq_num、hb_fq_seller_percent使用这两个扩展参数，则启用花呗分期
	
	/**
	 * 条码支付
	 */
	public static String barCodePay(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," +//必传
				"\"total_amount\":"+alipayParam.getTotal_amount()+"," +//必传
				"\"auth_code\":\""+alipayParam.getAuth_code()+"\"," +//必传
				"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"," +//必传
				"\"subject\":\""+alipayParam.getSubject()+"\","+//必传
				
				(alipayParam.getDiscountable_amount()!=null?("\"discountable_amount\":"+alipayParam.getDiscountable_amount()+","):"") +
				(alipayParam.getStore_id()!=null?("\"store_id\":\""+alipayParam.getStore_id()+"\","):"") +
				(alipayParam.getTerminal_id()!=null?("\"terminal_id\":\""+alipayParam.getTerminal_id()+"\","):"") +
				(alipayParam.getOperator_id()!=null?("\"operator_id\":\""+alipayParam.getOperator_id()+"\","):"") +
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"") +
				"\"extend_params\":{" +
					(alipayParam.getSys_service_provider_id()!=null?("\"sys_service_provider_id\":\""+alipayParam.getSys_service_provider_id()+"\","):"" )+
					(alipayParam.getHb_fq_num()!=null?("\"hb_fq_num\":\""+alipayParam.getHb_fq_num()+"\","):"" )+
					(alipayParam.getHb_fq_seller_percent()!=null?("\"hb_fq_seller_percent\":\""+alipayParam.getHb_fq_seller_percent()+"\","):"") +
					"\"TRANS_MEMO\":\"当面付\""+	
				"},"+
				
				"\"scene\":\"bar_code\"," +//条码支付固定传入bar_code
				"\"product_code\":\"FACE_TO_FACE_PAYMENT\"" +
		 "}";
		return request;
	}
	
	/**
	 * 声波付
	 */
	public static String waveCodePay(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," + //必传
				"\"total_amount\":"+alipayParam.getTotal_amount()+"," + //必传
				"\"auth_code\":\""+alipayParam.getAuth_code()+"\"," + //必传
				"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"," + //必传
				"\"subject\":\""+alipayParam.getSubject()+"\","+//必传
				
				(alipayParam.getDiscountable_amount()!=null?("\"discountable_amount\":"+alipayParam.getDiscountable_amount()+","):"") +
				(alipayParam.getStore_id()!=null?("\"store_id\":\""+alipayParam.getStore_id()+"\","):"") +
				(alipayParam.getTerminal_id()!=null?("\"terminal_id\":\""+alipayParam.getTerminal_id()+"\","):"") +
				(alipayParam.getOperator_id()!=null?("\"operator_id\":\""+alipayParam.getOperator_id()+"\","):"" )+
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"") +
				"\"extend_params\":{" +
						(alipayParam.getSys_service_provider_id()!=null?("\"sys_service_provider_id\":\""+alipayParam.getSys_service_provider_id()+"\","):"") +
						(alipayParam.getHb_fq_num()!=null?("\"hb_fq_num\":\""+alipayParam.getHb_fq_num()+"\","):"" )+
						(alipayParam.getHb_fq_seller_percent()!=null?("\"hb_fq_seller_percent\":\""+alipayParam.getHb_fq_seller_percent()+"\","):"") +
						"\"TRANS_MEMO\":\"当面付\""+	
				"},"+
				
				"\"scene\":\"wave_code\"," +//条码支付固定传入bar_code
				"\"product_code\":\"FACE_TO_FACE_PAYMENT\"" +
		 "}";
		return request;
	}

	/**
	 * 扫码付
	 */
	public static String scanCodePay(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," + //必传
				"\"total_amount\":"+alipayParam.getTotal_amount()+"," + //必传
				"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"," + //必传
				"\"subject\":\""+alipayParam.getSubject()+"\","+//必传
				
				(alipayParam.getDiscountable_amount()!=null?("\"discountable_amount\":"+alipayParam.getDiscountable_amount()+","):"" )+
				(alipayParam.getStore_id()!=null?("\"store_id\":\""+alipayParam.getStore_id()+"\","):"") +
				(alipayParam.getTerminal_id()!=null?("\"terminal_id\":\""+alipayParam.getTerminal_id()+"\","):"") +
				(alipayParam.getOperator_id()!=null?("\"operator_id\":\""+alipayParam.getOperator_id()+"\","):"" )+
				(alipayParam.getEnable_pay_channels()!=null?("\"enable_pay_channels\":\""+alipayParam.getEnable_pay_channels()+"\","):"") +
				(alipayParam.getDisable_pay_channels()!=null?("\"disable_pay_channels\":\""+alipayParam.getDisable_pay_channels()+"\","):"" )+
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"" )+
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"" )+
				"\"extend_params\":{" +
						(alipayParam.getSys_service_provider_id()!=null?("\"sys_service_provider_id\":\""+alipayParam.getSys_service_provider_id()+"\","):"") +
						(alipayParam.getHb_fq_num()!=null?("\"hb_fq_num\":\""+alipayParam.getHb_fq_num()+"\","):"" )+
						(alipayParam.getHb_fq_seller_percent()!=null?("\"hb_fq_seller_percent\":\""+alipayParam.getHb_fq_seller_percent()+"\","):"" )+
						"\"TRANS_MEMO\":\"扫码付\""+	
				"},"+
						
				"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"" + //必传
		 "}";
		return request;
	}
	
	/**
	 * app支付
	 */
	public static String appPay(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," + //必传
				"\"total_amount\":"+alipayParam.getTotal_amount()+"," + //必传
				"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"," + //必传
				"\"subject\":\""+alipayParam.getSubject()+"\","+//必传
				
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"" )+
				(alipayParam.getPassback_params()!=null?("\"passback_params\":\""+alipayParam.getPassback_params()+"\","):"") +
				(alipayParam.getStore_id()!=null?("\"store_id\":\""+alipayParam.getStore_id()+"\","):"") +
				(alipayParam.getEnable_pay_channels()!=null?("\"enable_pay_channels\":\""+alipayParam.getEnable_pay_channels()+"\","):"") +
				(alipayParam.getDisable_pay_channels()!=null?("\"disable_pay_channels\":\""+alipayParam.getDisable_pay_channels()+"\","):"") +
				"\"extend_params\":{" +
						(alipayParam.getSys_service_provider_id()!=null?("\"sys_service_provider_id\":\""+alipayParam.getSys_service_provider_id()+"\","):"") +
						(alipayParam.getHb_fq_num()!=null?("\"hb_fq_num\":\""+alipayParam.getHb_fq_num()+"\","):"") +
						(alipayParam.getHb_fq_seller_percent()!=null?("\"hb_fq_seller_percent\":\""+alipayParam.getHb_fq_seller_percent()+"\","):"") +
						"\"TRANS_MEMO\":\"线上支付\""+	
				"},"+
				
				"\"product_code\":\"QUICK_MSECURITY_PAY\"" +
		 "}";
		return request;
	}
	
	/**
	 * wap支付
	 */
	public static String wapPay(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," + //必传
				"\"total_amount\":"+alipayParam.getTotal_amount()+"," + //必传
				//"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"," + //必传
				"\"subject\":\""+alipayParam.getSubject()+"\","+//必传
				
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"") +
				(alipayParam.getPassback_params()!=null?("\"passback_params\":\""+alipayParam.getPassback_params()+"\","):"" )+
				(alipayParam.getStore_id()!=null?("\"store_id\":\""+alipayParam.getStore_id()+"\","):"") +
				(alipayParam.getQuit_url()!=null?("\"quit_url\":\""+alipayParam.getQuit_url()+"\","):"") +
				(alipayParam.getEnable_pay_channels()!=null?("\"enable_pay_channels\":\""+alipayParam.getEnable_pay_channels()+"\","):"") +
				(alipayParam.getDisable_pay_channels()!=null?("\"disable_pay_channels\":\""+alipayParam.getDisable_pay_channels()+"\","):"") +
				"\"extend_params\":{" +
						(alipayParam.getSys_service_provider_id()!=null?("\"sys_service_provider_id\":\""+alipayParam.getSys_service_provider_id()+"\","):"") +
						(alipayParam.getHb_fq_num()!=null?("\"hb_fq_num\":\""+alipayParam.getHb_fq_num()+"\","):"" )+
						(alipayParam.getHb_fq_seller_percent()!=null?("\"hb_fq_seller_percent\":\""+alipayParam.getHb_fq_seller_percent()+"\","):"") +
						"\"TRANS_MEMO\":\"线上支付\""+	
				"},"+
				
				"\"product_code\":\"QUICK_WAP_WAY\"" +
		 "}";
		log.info("支付宝请求参数："+request);
		return request;
	}
	
	
	/**
	 * pc支付
	 */
	public static String pcPay(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," + //必传
				"\"total_amount\":"+alipayParam.getTotal_amount()+"," + //必传
				"\"timeout_express\":\""+alipayParam.getTimeout_express()+"\"," + //必传
				"\"subject\":\""+alipayParam.getSubject()+"\","+//必传
				
				(alipayParam.getBody()!=null?("\"body\":\""+alipayParam.getBody()+"\","):"") +
				(alipayParam.getPassback_params()!=null?("\"passback_params\":\""+alipayParam.getPassback_params()+"\","):"") +
				(alipayParam.getEnable_pay_channels()!=null?("\"enable_pay_channels\":\""+alipayParam.getEnable_pay_channels()+"\","):"")+
				(alipayParam.getDisable_pay_channels()!=null?("\"disable_pay_channels\":\""+alipayParam.getDisable_pay_channels()+"\","):"") +
				"\"extend_params\":{" +
						(alipayParam.getSys_service_provider_id()!=null?("\"sys_service_provider_id\":\""+alipayParam.getSys_service_provider_id()+"\","):"") +
						(alipayParam.getHb_fq_num()!=null?("\"hb_fq_num\":\""+alipayParam.getHb_fq_num()+"\","):"") +
						(alipayParam.getHb_fq_seller_percent()!=null?("\"hb_fq_seller_percent\":\""+alipayParam.getHb_fq_seller_percent()+"\","):"") +
						"\"TRANS_MEMO\":\"线上支付\""+	
				"},"+
						
				"\"product_code\":\"FAST_INSTANT_TRADE_PAY\"" +
		 "}";
		return request;
	}

	/**
	 * 统一收单线下交易查询
	 */
	public static String tradeQuery(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_biz_no()+"\"," + //必传
				"\"trade_no\":\""+alipayParam.getTrade_no()+"\"" + //必传
		 "}";
		return request;
		
	}
	
	/**
	 * 统一收单交易撤销接口
	 */
	public static String cancel(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_biz_no()+"\"," + //必传
				"\"trade_no\":\""+alipayParam.getTrade_no()+"\"" + //必传
		 "}";
		return request;
		
	}
	
	/**
	 * 统一收单交易退款接口 
	 */
	public static String refund(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_trade_no\":\""+alipayParam.getOut_trade_no()+"\"," + //必传
				"\"trade_no\":\""+alipayParam.getTrade_no()+"\"," + //必传
				
				(alipayParam.getRefund_reason()!=null?("\"refund_reason\":\""+alipayParam.getRefund_reason()+"\","):"") +
				(alipayParam.getOut_request_no()!=null?("\"out_request_no\":\""+alipayParam.getOut_request_no()+"\","):"" )+
				(alipayParam.getOperator_id()!=null?("\"operator_id\":\""+alipayParam.getOperator_id()+"\","):"" )+
				(alipayParam.getStore_id()!=null?("\"store_id\":\""+alipayParam.getStore_id()+"\","):"") +
				(alipayParam.getTerminal_id()!=null?("\"terminal_id\":\""+alipayParam.getTerminal_id()+"\","):"") +
				
				"\"refund_amount\":"+alipayParam.getRefund_amount()+"" + //必传		
		 "}";
		log.info("refund:"+request);
		return request;
		
	}
	

	/**
	 * 查询对账单下载地址
	 */
	public static String downloadurl(AlipayParam alipayParam) {
		String request="{" + 
				"\"bill_type\":\""+alipayParam.getBill_type()+"\"," + //必传
				"\"bill_date\":\""+alipayParam.getBill_date()+"\"" + //必传	
		 "}";
		return request;
		
	}
	
	
	
	/**
	 * 电商户单笔转账到支付宝账户
	 */
	public static String transfer(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_biz_no\":\""+alipayParam.getOut_biz_no()+"\"," + //必传
				"\"payee_type\":\""+alipayParam.getPayee_type()+"\"," + //必传
				"\"payee_account\":\""+alipayParam.getPayee_account()+"\"," + //必传
				
				
				(alipayParam.getPayer_show_name()!=null?("\"payer_show_name\":\""+alipayParam.getPayer_show_name()+"\","):"") +
				(alipayParam.getPayee_real_name()!=null?("\"payee_real_name\":\""+alipayParam.getPayee_real_name()+"\","):"") +
				(alipayParam.getRemark()!=null?("\"remark\":\""+alipayParam.getRemark()+"\","):"") +
				
						
				"\"amount\":\""+alipayParam.getAmount()+"\""+//必传
		 "}";
		log.info(request);
		return request;
	}
	
	/**
	 * 转账查询
	 */
	public static String transferQuery(AlipayParam alipayParam) {
		String request="{" + 
				"\"out_biz_no\":\""+alipayParam.getOut_biz_no()+"\"," + //必传
				"\"order_id\":\""+alipayParam.getOrder_id()+"\"" + //必传
		 "}";
		return request;
		
	}
	
	/**
	 * 创建现金活动
	 */
	public static String createCash(AlipayParam alipayParam) {
		String request="{" + 
				"\"coupon_name\":\""+alipayParam.getCoupon_name()+"\"," + //必传
				"\"prize_type\":\""+alipayParam.getPrize_type()+"\"," + //必传
				"\"total_money\":\""+alipayParam.getTotal_money()+"\"," + //必传
				"\"total_num\":\""+alipayParam.getTotal_num()+"\"," + //必传
				"\"prize_msg\":\""+alipayParam.getPrize_msg()+"\"," + //必传
				"\"start_time\":\""+alipayParam.getStart_time()+"\"," + //必传
				"\"end_time\":\""+alipayParam.getEnd_time()+"\"," + //必传
				
				(alipayParam.getSend_freqency()!=null?("\"send_freqency\":\""+alipayParam.getSend_freqency()+"\","):"") +
				
				"\"merchant_link\":\""+alipayParam.getMerchant_link()+"\"" + //必传
		 "}";
		return request;
	}
	
	/**
	 * 发放红包给用户
	 */
	public static String sendCash(AlipayParam alipayParam) {
		String request="{" + 
				"\"crowd_no\"\":"+alipayParam.getPrize_type()+"\"," + //必传
				
				(alipayParam.getUser_id()!=null?("\"user_id\":\""+alipayParam.getUser_id()+"\","):"" )+
				(alipayParam.getOut_biz_no()!=null?("\"out_biz_no\":\""+alipayParam.getOut_biz_no()+"\","):"" )+
				
				"\"login_id\":\""+alipayParam.getLogin_id()+"\"" + //必传
		 "}";
		return request;
	}
	
	/**
	 * 更改现金活动状态
	 */
	public static String updateCashStatus(AlipayParam alipayParam) {
		String request="{" + 
				"\"crowd_no\":\""+alipayParam.getCrowd_no()+"\"," + //必传				
				"\"camp_status\":\""+alipayParam.getCamp_status()+"\"" + //必传
		 "}";
		return request;
	}
	
	/**
	 * 现金活动列表查询
	 */
	public static String cashQuery(AlipayParam alipayParam) {
		String request="{" + 
				(alipayParam.getCamp_status()!=null?("\"camp_status\":\""+alipayParam.getCamp_status()+"\","):"") +
		
				"\"page_size\":\""+alipayParam.getPage_size()+"\"," + //必传				
				"\"page_index\":\""+alipayParam.getPage_index()+"\"" + //必传
		 "}";
		return request;
	}
	
	/**
	 * 现金活动详情查询
	 */
	public static String cashDetailQuery(AlipayParam alipayParam) {
		String request="{" + 		
				"\"crowd_no\":\""+alipayParam.getCrowd_no()+"\"," + //必传				
		 "}";
		return request;
	}
	
	/**
	 * 余利宝申购
	 */
	public static String purchase(AlipayParam alipayParam) {
		String request="{" + 		
				"\"fund_code\":\""+alipayParam.getFund_code()+"\"," + //必传				
				"\"amount\":\""+alipayParam.getAmount()+"\"," + //必传				
				"\"currency\":\""+alipayParam.getCurrency()+"\"," + //必传				
				"\"out_biz_no\":\""+alipayParam.getOut_biz_no()+"\"" + //必传				
		 "}";
		return request;
	}
	
	/**
	 * 余利宝赎回
	 */
	public static String ransom(AlipayParam alipayParam) {
		String request="{" + 		
				"\"fund_code\":\""+alipayParam.getFund_code()+"\"," + //必传				
				"\"amount\":\""+alipayParam.getAmount()+"\"," + //必传				
				"\"currency\":\""+alipayParam.getCurrency()+"\"," + //必传				
				"\"ransom_mode\":\""+alipayParam.getRansom_mode()+"\"," + //必传				
				"\"out_biz_no\":\""+alipayParam.getOut_biz_no()+"\"" + //必传				
		 "}";
		return request;
	}
	
	/**
	 * 余利宝历史交易查询
	 */
	public static String historyQuery(AlipayParam alipayParam) {
		String request="{" + 		
				"\"fund_code\":\""+alipayParam.getFund_code()+"\"," + //必传				
				"\"start_date\":\""+alipayParam.getStart_date()+"\"," + //必传				
				"\"end_date\":\""+alipayParam.getEnd_date()+"\"," + //必传				
				"\"page\":\""+alipayParam.getPage()+"\"," + //必传				
				"\"page_size\":\""+alipayParam.getPage_size()+"\"" + //必传				
		 "}";
		return request;
	}
	
	/**
	 * 余利宝账户和收益查询
	 */
	public static String accountQuery(AlipayParam alipayParam) {
		String request="{" + 		
				"\"fund_code\":\""+alipayParam.getFund_code()+"\"" + //必传							
		 "}";
		return request;
	}
	
	/**
	 * 查询余利宝行情信息
	 */
	public static String priceQuery(AlipayParam alipayParam) {
		String request="{" + 		
				"\"fund_code\":\""+alipayParam.getFund_code()+"\"," + //必传		
				"\"start_date\":\""+alipayParam.getStart_date()+"\"," + //必传				
				"\"end_date\":\""+alipayParam.getEnd_date()+"\"" + //必传	
		 "}";
		return request;
	}
}
